package com.yjz.leetcode.合并两个有序链表;

/**
 * @author :yuanJinZhong
 * @description:合并有序链表
 * @date :2018/7/16-15:25
 */
public class Solution {
  public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
    if (l1 == null || l2 == null) {
      if (l1 == null && l2 == null) {
        return null;
      } else {
        return l1 == null ? l2 : l1;
      }
    }
    ListNode result = null;

    if (l1.val < l2.val) {
      result = l1;
      result.next = mergeTwoLists(l1.next, l2);
    } else {
      result = l2;
      result.next = mergeTwoLists(l1, l2.next);
    }

    return result;
  }
}
